package com.human.server.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.human.server.entity.Kpis;
import com.human.server.model.R;
import com.human.server.model.request.KpisRequest;
import com.human.server.service.impl.KpisServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/human/kpis")
public class KpisController {

    @Autowired
    private KpisServiceImpl kpisService;

    /**
     * 分页
     * @param request
     * @return
     */
    @RequestMapping("/page")
    public R page(@RequestBody KpisRequest request) {
        return R.success(kpisService.page(request, new LambdaQueryWrapper<Kpis>()
                .like(StrUtil.isNotBlank(request.getName()), Kpis::getName, request.getName())
                .like(StrUtil.isNotBlank(request.getType()), Kpis::getType, request.getType())
                ));
    }

    /**
     * 新增
     * @param kpis
     * @return
     */
    @RequestMapping("/add")
    public R add(@RequestBody Kpis kpis) {
        return R.success(kpisService.save(kpis));
    }

    /**
     * 更新
     * @param kpis
     * @return
     */
    @RequestMapping("/update")
    public R update(@RequestBody Kpis kpis) {
        return R.success(kpisService.updateById(kpis));
    }

    /**
     * 删除
     * @param kpis
     * @return
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Kpis kpis) {
        return R.success(kpisService.removeById(kpis));
    }

    /**
     * 查询
     * @param kpis
     * @return
     */
    @RequestMapping("/query")
    public R query(@RequestBody Kpis kpis) {
        return R.success(kpisService.getById(kpis.getId()));
    }

    /**
     * 列表
     * @return
     */
    @RequestMapping("/list")
    public R list() {
        return R.success(kpisService.list());
    }
}
